<template>
  <div class="phptoinfo">
    <h3 class="tit">{{ Photoinfo.title }}</h3>
    <p class="subtitle">
      <span>发表时间：{{ Photoinfo.add_time | dataFormat }}</span>
      <span>点击次数：{{ Photoinfo.click }} 次</span>
    </p>
    <hr>
    <!-- 缩略图 -->
    <div class="thumbs">
      <vue-preview :slides="slide1" class="imgPrev"></vue-preview>
    </div>
    <!-- 文本 -->
    <div class="content" v-html="Photoinfo.content">
    </div>

    <!-- 评论 -->
    <hr>
    <cmt-box></cmt-box>
  </div>
</template>

<script>
  import comment from "../../subcompontents/comment.vue";
  export default {
    data() {
      return {
        id: this.$route.params.id,
        Photoinfo: {},
        slide1: []
      }
    },
    created() {
      this.getPhotoinfo();
      this.getthumbs();
    },
    methods: {
      getPhotoinfo() {
        this.$http.get('api/getimageInfo/' + this.id).then(result => {
          if (result.body.status == 0) {
            this.Photoinfo = result.body.message[0]
          } else {
            Toast('数据加载失败')
          }
        })
      },
      getthumbs() {
        this.$http.get('api/getthumimages/' + this.id).then(result => {
          if (result.body.status === 0) {
            result.body.message.forEach(item => {
              item.w = 600; //设置以大图浏览时的宽度
              item.h = 400; //设置以大图浏览时的高度
              item.src = item.src; //大图
              item.msrc = item.src; //小图
            });
            this.slide1 = result.body.message;
            console.log(this.slide1)
          }
        })
      },
      handleClose() {
        console.log('close event')
      }
    },
    components: {
      "cmt-box": comment
    }
  }
</script>

<style lang="scss" scoped>
  .phptoinfo {
    padding: 4px;

    .tit {
      text-align: center;
      font-size: 16px;
      line-height: 36px;
      position: absolute;
      top: 50%;
      transform: translateY(-50%)
    }

    .subtitle {
      display: flex;
      justify-content: space-between
    }

    .content {
      font-size: 14px;
      line-height: 1.8;
    }

    .thumbs {
      /deep/ .my-gallery {
        display: flex;
        flex-wrap: wrap;

        figure {
          width: 30%;
          margin: 5px;

          img {
            width: 100%;
          }
        }
      }
    }

  }
</style>